//
//  H_LoginAndRegisterVC.m
//  Honey
//
//  Created by 贾亚涵 on 16/5/7.
//  Copyright © 2016年 贾亚涵. All rights reserved.
//

#import "H_LoginAndRegisterVC.h"
#import "H_TabBarController.h"
#import "H_LoginVC.h"
#import "H_RegisterVC.h"

#define Enter_Button 100
#define Register_Button 200

@interface H_LoginAndRegisterVC ()
{
    UIImageView * _iconIV;
    UIButton * _LoginBtn;
    UIButton * _RegistBtn;
}

@end

@implementation H_LoginAndRegisterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createLoginAndRegisterView];
//    [self performSelector:@selector(change) withObject:nil afterDelay:2];
        // 判断是否是第一次启动，如果不是就直接进入，不显示UIScrollView
//        if (![[[NSUserDefaults standardUserDefaults] objectForKey:New_Function_Version_Flag] boolValue])
//        {
//            [[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:YES] forKey:New_Function_Version_Flag];
//    
//            [self initScrollFuction];
//        }

}

-(void)createLoginAndRegisterView
{
    _iconIV = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width/2-30, 150, 60, 60)];
    _iconIV.image = [UIImage imageNamed:@"i"];
    [self.view addSubview:_iconIV];
    _LoginBtn = [self addButtonWithName:@"登 录" Tag:Enter_Button Rect:CGRectMake(20, CGRectGetMaxY(_iconIV.frame)+60, Screen_Width-40, 30)];
    [_LoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:_LoginBtn];
    _RegistBtn = [self addButtonWithName:@"注 册" Tag:Register_Button Rect:CGRectMake(20, CGRectGetMaxY(_LoginBtn.frame)+25, Screen_Width-40, 30)];
    [_RegistBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:_RegistBtn];
}
#pragma mark- UIButton
-(UIButton *)addButtonWithName:(NSString *)name Tag:(NSInteger)tag Rect:(CGRect)rect
{
    UIButton *btn = [[UIButton alloc] initWithFrame:rect];
    
    btn.tag = tag;
    
    [btn setTitle:name forState:UIControlStateNormal];
    
    btn.backgroundColor = [UIColor orangeColor];
    
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.layer.cornerRadius = 8.0f;
    
    [btn addTarget:self action:@selector(BtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
}

-(void)BtnClicked:(id)sender
{
    if (sender && [sender isKindOfClass:[UIButton class]])
    {
        UIButton * button = (UIButton *)sender;
        
        switch (button.tag)
        {
            case Enter_Button:
            {
                H_LoginVC * _loginVC = [H_LoginVC new];
                UINavigationController * _loginNaC = [[UINavigationController alloc]initWithRootViewController:_loginVC];
                [self presentViewController:_loginNaC animated:YES completion:^{
                    
                }];

            }
                break;
            case Register_Button:
            {
                H_RegisterVC * _registerVC = [H_RegisterVC new];
                UINavigationController * _registerNaC = [[UINavigationController alloc]initWithRootViewController:_registerVC];
                [self presentViewController:_registerNaC animated:YES completion:^{
                    
                }];

                
            }
                break;
                
            default:
                break;
        }
    }
}

-(void)change{
//    H_TabBarController * tabBar = [H_TabBarController new];
//    [UIApplication sharedApplication].keyWindow.rootViewController = tabBar;
    
}

-(void)initScrollFuction
{
        NSMutableArray * imageLists = [NSMutableArray array];

        for (int index = 0; index<4; index++)
        {
            NSString * imageName = [NSString stringWithFormat:@"start-up-%d.png",index+1];
            [imageLists addObject:imageName];
        }

        H_ScrollFuctionV * newView = (H_ScrollFuctionV *)[H_ScrollFuctionV showScrollFuction:HWScrollViewTypeNewFuction ImageArray:imageLists ];
        [self.view addSubview:newView];

}

@end
